<%--
  Created by IntelliJ IDEA.
  User: 甘汝雷
  Date: 2017/5/2
  Time: 14:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--解析表达式--%>
<%@ page isELIgnored="false" %>
<%--引入jstl--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%--引入springMVC form--%>
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="page" uri="/xianzhiOA/pageTag" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>编辑模块</title>
    <script type="application/javascript">
        function ToempShowPage() {
            window.location.href = "${pageContext.request.contextPath}/Module/selModuleAll.emp";
        }
        function go() {
            var errors = document.getElementById("errors");
            check();
            var sub = document.getElementById("sub").value;
            if (${module.moduleId!=0&&module.moduleId!=null}) {
                document.getElementById("moduleForm").action = "${pageContext.request.contextPath}/Module/updateModule.emp";
            }
            if (errors.innerHTML!="模块名称已存在"&&sub==0) document.getElementById("moduleForm").submit();

        }
        <!--表单验证-->
        function check(){
            var stageList1 = document.getElementById("stageList1");
            var j = document.getElementById("num").value;
            var moduleName = document.getElementById("moduleName").value;
            var errors = document.getElementById("errors");
            errors.innerHTML = "";
            var list = new Array;
            var l = 0,stageP=0,stageA=0;
            var w = "",p="",a="";
            if (moduleName==""){
                 errors.innerHTML = "模块名不能为空";
                return false;
            }
            for (var k = 1;k<=j;k++){
                var sp = document.getElementById("sp"+k);<!--计划比例-->
                var sa = document.getElementById("sa"+k);<!--实际比例-->
                var sw = document.getElementById("sw"+k);<!--所属周期-->
                var msgP = document.getElementById("msgP"+k);
                var msgA = document.getElementById("msgA"+k);
                var msgW = document.getElementById("msgW"+k);
                msgP.innerHTML = "";
                msgA.innerHTML = "";
                msgW.innerHTML = "";
                var z= /^[0-9]*[.]*[0-9]*$/;
                if (z.test(sp.value)&&sp.value!=""){
                    if (parseInt(sp.value)>0&&parseInt(sp.value)<=100){
                        stageP += parseInt(sp.value);
                        list.push(sp.value);
                    }else {
                        msgP.innerHTML = "数字必须在0~100之间";
                        l++;
                    }
                }else {
                    msgP.innerHTML = "请输入数字";
                    l++;
                }
                if (z.test(sa.value)&&sa.value!=""){
                    if (parseInt(sa.value)>0&&parseInt(sa.value)<=100){
                        stageA += parseInt(sa.value);
                        list.push(sa.value);
                    }else {
                        msgA.innerHTML = "数字必须在0~100之间";
                        l++;
                    }
                }else {
                    msgA.innerHTML = "请输入数字";
                    l++;
                }
                if (sw.value!=""){
                    list.push(sw.value);
                }else {
                    msgW.innerHTML = "请选择周期"
                    l++;
                }
            }
            if (l>0){
                document.getElementById("sub").value = l;
                return false;
            }else {
                stageList1.value = list;
                document.getElementById("sub").value = 0;
                return true;
            }
        }
        <!--动态验证模块名称是否重复-->
        function repetition() {
            var moduleId = ${module.moduleId};
            var moduleName = document.getElementById("moduleName").value;
            var moduleProject = document.getElementById("moduleProject").value;
            var errors = document.getElementById("errors");
            if (moduleId=='0') {
                $.ajax({
                    url: '${pageContext.request.contextPath}/Module/selectByModuleName.emp',
                    data: {moduleName: moduleName,moduleProject: moduleProject},
                    type: 'post',
                    dataType: 'json',
                    success: function (data) {
                        errors.innerHTML = "";
                        if (data) {
                            errors.innerHTML = "模块名称已存在";
                        }
                    }
                })
            }
        }
    </script>
</head>
<body>
<!--头部开始-->
<jsp:include page="headerBack.jsp"></jsp:include>
<!-- 导航 -->
<jsp:include page="leftBack.jsp"></jsp:include>

<!--内容页-->
<div class="main">
    <!--内容页头部-->
    <div class="page-header">
        <div class="pull-left">
            <ol class="breadcrumb visible-sm visible-md visible-lg">
                <li><a href="${pageContext.request.contextPath}/Login/goHomePage"><i class="icon fa fa-home"></i>主页</a></li>
                <li class="active"><i class="fa fa-pencil"></i>模板</li>
            </ol>
        </div>
        <div class="pull-right">
            <h2>主页</h2>
        </div>
    </div>
    <div class="templet">
        <sf:form id="moduleForm" action="${pageContext.request.contextPath}/Module/addModule.emp"
                 modelAttribute="module" class="templet_form" method="post" onsubmit="return check();">
            <h4 class="templet_h4">模块<c:if test="${i!=null}">${i}</c:if></h4>
            <div class="templet_all col-md-12" style="margin-left: 30px">
                <sf:input type="hidden" path="moduleId" id="moduleId"/>
                <sf:input type="hidden" path="stageList1" />
                <input id="sub" type="hidden"/>
                <input id="num" type="hidden" name="num" value="0">
                <div class="form-group col-md-4">
                    <span class="new_name">归属项目：</span><br/>
                    <sf:select id="moduleProject" path="moduleProject" style="width: 162px" onclick="repetition();">
                        <sf:options items="${projectList}" itemLabel="projectName" itemValue="projectId"/>
                    </sf:select>
                </div>
                <div class="form-group col-md-4">
                    <span class="new_name">模块：</span><br/>
                    <sf:input id ="moduleName" path="moduleName" type="text" onblur="repetition();"/>
                    <sf:errors path="moduleName"/>
                    <span style="color: red" id="errors">${errors.moduleName}</span>
                </div>
                <c:if test="${userLogin.empRole.equals('1')}">
                <div class="form-group col-md-4">
                    <span class="new_name">负责人：</span><br/>
                    <sf:select path="moduleEmp" style="width: 162px">
                        <sf:options items="${empList}" itemLabel="empName" itemValue="empId"/>
                    </sf:select>
                </div>
                </c:if>
                <hr style="width: 100%">
                    <div class="templet_icon2">
                        <h4 class="templet_h4">阶段</h4>
                        <a href="#" class="templet_a1" onclick='addElement()'><span class="fa fa-plus"></span></a>
                        <a href="#" class="templet_a2" onclick='dropElement()'><span class="fa fa-minus"></span></a><br>
                    </div>
            </div>
            <div id="course" class="col-md-12" style="margin-left: 30px">
                <c:if test="${module.stageList[0].stageId!=null}">
                    <c:forEach begin="0" end="${stageSize-1}" var="s">
                        <sf:input path="stageList[${s}].stageId" type="hidden"/>
                        <div class="form-group col-md-4" id="course"><span class="new_name">计划（比例） ： </span><br/>
                            <sf:input path="stageList[${s}].stagePlan" type="text" class="new_in"/> %
                        </div>
                        <div class="form-group col-md-4" id="course"><span class="new_name">实际（比例） ： </span><br/>
                            <sf:input path="stageList[${s}].stageActual" type="text" class="new_in"/> %
                        </div>
                        <div class="form-group col-md-4" id="course"><span class="new_name">所属周期 ： </span><br/>
                            <sf:input path="stageList[${s}].stageWeek" type="date"/>&nbsp;&nbsp;&nbsp;
                            <a href="${pageContext.request.contextPath}/Module/stageIsdelete.emp?stageId=${module.stageList[s].stageId}&moduleId=${module.moduleId}" role="button" data-toggle="modal">
                                <i class="fa fa-times"></i></a>
                        </div>
                    </c:forEach>
                </c:if>
            </div>
            <button class="btn btn-primary" onclick="go()" type="button" style="margin-left: 40px;margin-top: 30px">提交</button>
            <button type="button" onclick="ToempShowPage()" class="btn btn-primary" style="margin-left: 20px;margin-top: 30px">取消</button>
            <span id="msg" style="color: red"></span>
        </sf:form>
    </div>
    <div id="aaa"></div>
</div>
<script type="application/javascript">
    var i = 1;
    function addElement() {
        var div = document.createElement('div');
        div.innerHTML = '<div class="form-group col-md-4" id="course"><span class="new_name">计划（比例） ： </span><br/>' +
            '<input id="sp'+i+'" name="stagePlan'+i+'" type="text" class="new_in"> %<span id="msgP'+i+'" style="color: red"></span></div>' +
            '<div class="form-group col-md-4" id="course"><span class="new_name">实际（比例） ： </span><br/>' +
            '<input id="sa'+i+'" name="stageActual'+i+'" type="text" class="new_in"> %<span id="msgA'+i+'" style="color: red"></span></div>' +
            '<div class="form-group col-md-4" id="course"><span class="new_name">所属周期 ： </span><br/>' +
            '<input id="sw'+i+'" name="stageWeek'+i+'" type="date" onchange="dateVerify('+i+')"/>' +
            '<span id="msgW'+i+'" style="color: red"></span></div>';
        div.id = 'Elem' + i;
        document.getElementById('course').appendChild(div);
        document.getElementById("num").value = i;
        i++;
    }
    function dropElement() {
        var aaa = document.getElementById('Elem' + (i - 1));
        document.getElementById('course').removeChild(aaa);
        i--;
    }

//    jeDate({
//        dateCell:"#indate",
//        format:"YYYY-MM-DD",
//        isTime:false,
//        minDate:"2014-09-19 00:00:00"});
//    jeDate({
//        dateCell:"#indate1",
//        format:"YYYY-MM-DD",
//        isTime:false,
//        minDate:"2014-09-19 00:00:00"})
</script>
<%--<script type="text/javascript" src="${pageContext.request.contextPath}/dist/backEnd/js/datetime.js"></script>--%>
</body>
</html>